<%--
  Created by IntelliJ IDEA.
  User: 27716
  Date: 2024/10/29
  Time: 19:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加</title>
    <script src="../../static/js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="../../static/css/css.css">
    <script>
        $(function () {
            getGoodsType();
            getSupplier();
        })

        function getGoodsType() {
            $.ajax({
                url: "/goodsType/goodsType",
                dataType: "json",
                success(res) {
                    for (let o of res) {
                        $("#goodsTypeId").append(`
                          <option value="\${o.goodsTypeId}">\${o.goodsTypeName}</option>
                        `)
                    }
                },
                error(){
                    alert("服务器出错")
                }
            })

        }

        function getSupplier() {
            $.ajax({
                url: "/supplier/getSupplier",
                dataType: "json",
                success(res) {
                    for (let o of res) {
                        $("#supplierId").append(`
                                <option value="\${o.supplierId}">\${o.supplierName}</option>
                            `)
                    }
                },
                error() {
                    alert("服务器出现问题")
                }
            })
        }
    </script>
</head>
<body>
商品编码： <input type="text" id="goodsCode"> <br>
商品名称： <input type="text" id="goodsName"> <br>
库存数量： <input type="text" id="inventoryQuantity"> <br>
<select id="goodsTypeId">
    <option value="">请选择</option>
</select> <br>
<select id="supplierId">
    <option value="">请选择</option>
</select>
<input type="button" value="添加" onclick="search()">
</body>
<script>
    function search(){
        let goodsCode = $("#goodsCode").val();
        let goodsName = $("#goodsName").val();
        let inventoryQuantity = $("#inventoryQuantity").val();
        let goodsTypeId = $("#goodsTypeId").val();
        let supplierId = $("#supplierId").val();
        let obj = {goodsCode,goodsName,inventoryQuantity,goodsTypeId,supplierId};
        $.ajax({
            url:"/goodschange/getAdd",
            type:"post",
            data:{reqInfos:JSON.stringify(obj)},
            dataType:"json",
            success(res){
                if(res === 200){
                    alert("添加成功");
                    location.href = "list.jsp";
                }
            }
        })
    }
</script>
</html>
